home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93a.txt
/
000107_icon-group-sender _Thu Apr 1 17:27:10 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-04-21
|
3KB
Received: by cheltenham.cs.arizona.edu; Fri, 9 Apr 1993 16:52:55 MST
Date: 1 Apr 93 17:27:10 GMT
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!msuinfo!uchinews!ellis!goer@ucbvax.Berkeley.EDU (Richard L. Goerwitz)
Organization: University of Chicago
Subject: Re: help an Icon rookie
Message-Id: <1993Apr1.172710.5099@midway.uchicago.edu>
References: <9346@kielo.uta.fi>
Sender: icon-group-request@cs.arizona.edu
To: icon-group@cs.arizona.edu
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
In article <9346@kielo.uta.fi> jere@uta.fi (Jere K{pyaho) writes:
>Can I ask stupid questions in this newsgroup? Thanks.
A beginner's question yours was. Not a *stupid* one. Beginners'
queries are the lifeblood of any newsgroup about any language that
isn't overwhelmed with traffic.
>Now, I understand that this
>
> procedure genchar( s, c )
> every i := ( s ? upto( c ) ) do
> write ( i )
> end
>
>outputs the positions of every character of 'c' in 's'.
>But how do I output the corresponding _characters_ in 's'?
To do this, you have to subscript. There are many ways to do it.
You can also use the scanning mechanism itself. One thing to nail
down beforehand is how to group scanning expressions for clarity.
Normally, it's best to make the scanning expression the outer con-
trol structure. This makes modification simpler. In the above pro-
cedure, though, there actually wasn't any reason to scan:
procedure genchar(s,c)
local i
every i := upto(c, s) do
write(i)
end
or better yet
procedure genchar(s,c)
local i
every write(upto(c, s))
end
If you want to output the actual character matched, then you just add
a subscripting mechanism:
procedure genchar(s,c)
local i
every i := upto(c, s) do
write(s[i])
end
or more compactly (but maybe less clearly):
procedure genchar(s,c)
local i
every write( s[upto(c, s)] )
end
I probably would have solved the problem myself in an entirely different
way, though, using scanning:
procedure genchar(s, c)
s ? {
while tab(upto(c)) do
write(move(1))
}
end
Or more compactly:
procedure genchar(s, c)
s ? while write( (tab(upto(c)), move(1)) )
end
Please don't hesitate to ask beginner questions here. This newsgroup
is not at all hostile to them. Please check my code before using it,
as I've had to write a lot of C lately, and I don't shift languages
very well.
--
-Richard L. Goerwitz goer%midway@uchicago.bitnet
goer@midway.uchicago.edu rutgers!oddjob!ellis!goer